import Taro from '@tarojs/taro'
import React, { Component } from 'react'
import { View, Text,Button } from '@tarojs/components'
import './index.less'
import { connect } from 'react-redux'
@connect(({ common }) => ({ common }))
export default class Index extends Component {

  componentWillMount() { }

  componentDidMount() { }

  componentWillUnmount() { }

  componentDidShow() { }

  componentDidHide() { }
  toTest = () => {
    Taro.navigateTo({
      url: '/pages/test/index?id=1'
    })
  }
  changeName() {
    this.props.dispatch({
      type: 'common/changeName',
      payload: {
        name: 'sss'
      }
    })
    this.props.dispatch({
      type: 'test/changeSex',
      payload: {
        sex: '女'
      }
    })
  }
  request() {
    this.props.dispatch({
      type: 'common/testRequest',
      payload: {
        data: { cc: '1' }
      }
    }).then(res => {
      console.log(res);
    })
  }

  render() {
    return (
      <View className='index'>
        <Button>{this.props.common.name}</Button>
        <Text onClick={() => { this.toTest() }} >点我去test页面 </Text>
        <View onClick={() => { this.changeName() }}>点我修改名字</View>
        <View onClick={() => { this.request() }}>点我测试发送请求</View>
      </View>
    )
  }
}
